From 9e5e63f0a147d0089e27c6b6af2bde70db77430c Mon Sep 17 00:00:00 2001 From: Owen Taylor Date: Thu, 28 Jan 1999 00:57:18 +0000 Subject: [PATCH] Hack scrollwheel support into the eventloop, by treating button 4-5 Wed Jan 27 18:40:50 1999 Owen Taylor * gtk/gtkmain.c (gtk_main_do_event): Hack scrollwheel support into the eventloop, by treating button 4-5 presses on scrolled windows and scrollbars specially. Put it here to keep the ugliness small and confined. (We need to intercept the normal propagation in any case to have this work reliably right now, since some subwidgets will trap the button presses) * gtk/gtkviewport.c (gtk_viewport_realize): Select for BUTTON_PRESS to support the above hack. --- ChangeLog | 13 ++++++++++++ ChangeLog.pre-2-0 | 13 ++++++++++++ ChangeLog.pre-2-10 | 13 ++++++++++++ ChangeLog.pre-2-2 | 13 ++++++++++++ ChangeLog.pre-2-4 | 13 ++++++++++++ ChangeLog.pre-2-6 | 13 ++++++++++++ ChangeLog.pre-2-8 | 13 ++++++++++++ gtk/gtkmain.c | 50 +++++++++++++++++++++++++++++++++++++++++----- gtk/gtkviewport.c | 4 +++- 9 files changed, 139 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5d6ca7eea5..2b4f312371 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +Wed Jan 27 18:40:50 1999 Owen Taylor + + * gtk/gtkmain.c (gtk_main_do_event): Hack scrollwheel + support into the eventloop, by treating button 4-5 + presses on scrolled windows and scrollbars specially. + Put it here to keep the ugliness small and confined. + (We need to intercept the normal propagation in any case + to have this work reliably right now, since some + subwidgets will trap the button presses) + + * gtk/gtkviewport.c (gtk_viewport_realize): Select for + BUTTON_PRESS to support the above hack. + Tue Jan 26 14:02:50 1999 Owen Taylor * gdk/gdkwindow.c (gdk_window_show/hide): Remove TimJ's diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 5d6ca7eea5..2b4f312371 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,16 @@ +Wed Jan 27 18:40:50 1999 Owen Taylor + + * gtk/gtkmain.c (gtk_main_do_event): Hack scrollwheel + support into the eventloop, by treating button 4-5 + presses on scrolled windows and scrollbars specially. + Put it here to keep the ugliness small and confined. + (We need to intercept the normal propagation in any case + to have this work reliably right now, since some + subwidgets will trap the button presses) + + * gtk/gtkviewport.c (gtk_viewport_realize): Select for + BUTTON_PRESS to support the above hack. + Tue Jan 26 14:02:50 1999 Owen Taylor * gdk/gdkwindow.c (gdk_window_show/hide): Remove TimJ's diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 5d6ca7eea5..2b4f312371 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,16 @@ +Wed Jan 27 18:40:50 1999 Owen Taylor + + * gtk/gtkmain.c (gtk_main_do_event): Hack scrollwheel + support into the eventloop, by treating button 4-5 + presses on scrolled windows and scrollbars specially. + Put it here to keep the ugliness small and confined. + (We need to intercept the normal propagation in any case + to have this work reliably right now, since some + subwidgets will trap the button presses) + + * gtk/gtkviewport.c (gtk_viewport_realize): Select for + BUTTON_PRESS to support the above hack. + Tue Jan 26 14:02:50 1999 Owen Taylor * gdk/gdkwindow.c (gdk_window_show/hide): Remove TimJ's diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 5d6ca7eea5..2b4f312371 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,16 @@ +Wed Jan 27 18:40:50 1999 Owen Taylor + + * gtk/gtkmain.c (gtk_main_do_event): Hack scrollwheel + support into the eventloop, by treating button 4-5 + presses on scrolled windows and scrollbars specially. + Put it here to keep the ugliness small and confined. + (We need to intercept the normal propagation in any case + to have this work reliably right now, since some + subwidgets will trap the button presses) + + * gtk/gtkviewport.c (gtk_viewport_realize): Select for + BUTTON_PRESS to support the above hack. + Tue Jan 26 14:02:50 1999 Owen Taylor * gdk/gdkwindow.c (gdk_window_show/hide): Remove TimJ's diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 5d6ca7eea5..2b4f312371 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,16 @@ +Wed Jan 27 18:40:50 1999 Owen Taylor + + * gtk/gtkmain.c (gtk_main_do_event): Hack scrollwheel + support into the eventloop, by treating button 4-5 + presses on scrolled windows and scrollbars specially. + Put it here to keep the ugliness small and confined. + (We need to intercept the normal propagation in any case + to have this work reliably right now, since some + subwidgets will trap the button presses) + + * gtk/gtkviewport.c (gtk_viewport_realize): Select for + BUTTON_PRESS to support the above hack. + Tue Jan 26 14:02:50 1999 Owen Taylor * gdk/gdkwindow.c (gdk_window_show/hide): Remove TimJ's diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 5d6ca7eea5..2b4f312371 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,16 @@ +Wed Jan 27 18:40:50 1999 Owen Taylor + + * gtk/gtkmain.c (gtk_main_do_event): Hack scrollwheel + support into the eventloop, by treating button 4-5 + presses on scrolled windows and scrollbars specially. + Put it here to keep the ugliness small and confined. + (We need to intercept the normal propagation in any case + to have this work reliably right now, since some + subwidgets will trap the button presses) + + * gtk/gtkviewport.c (gtk_viewport_realize): Select for + BUTTON_PRESS to support the above hack. + Tue Jan 26 14:02:50 1999 Owen Taylor * gdk/gdkwindow.c (gdk_window_show/hide): Remove TimJ's diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 5d6ca7eea5..2b4f312371 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,16 @@ +Wed Jan 27 18:40:50 1999 Owen Taylor + + * gtk/gtkmain.c (gtk_main_do_event): Hack scrollwheel + support into the eventloop, by treating button 4-5 + presses on scrolled windows and scrollbars specially. + Put it here to keep the ugliness small and confined. + (We need to intercept the normal propagation in any case + to have this work reliably right now, since some + subwidgets will trap the button presses) + + * gtk/gtkviewport.c (gtk_viewport_realize): Select for + BUTTON_PRESS to support the above hack. + Tue Jan 26 14:02:50 1999 Owen Taylor * gdk/gdkwindow.c (gdk_window_show/hide): Remove TimJ's diff --git a/gtk/gtkmain.c b/gtk/gtkmain.c index f573c9db11..62f337fa6e 100644 --- a/gtk/gtkmain.c +++ b/gtk/gtkmain.c @@ -29,6 +29,7 @@ #include "gtkmain.h" #include "gtkpreview.h" #include "gtkrc.h" +#include "gtkscrolledwindow.h" #include "gtkselection.h" #include "gtksignal.h" #include "gtktable.h" @@ -629,7 +630,7 @@ gtk_main_do_event (GdkEvent *event) { grab_widget = event_widget; } - + /* Not all events get sent to the grabbing widget. * The delete, destroy, expose, focus change and resize * events still get sent to the event widget because @@ -675,7 +676,49 @@ gtk_main_do_event (GdkEvent *event) case GDK_VISIBILITY_NOTIFY: gtk_widget_event (event_widget, event); break; - + + case GDK_BUTTON_PRESS: + case GDK_2BUTTON_PRESS: + case GDK_3BUTTON_PRESS: + /* We treat button 4-5 specially, assume we have + * a MS-style scrollwheel mouse, and try to find + * a plausible widget to scroll. We also trap + * button 4-5 double and triple clicks here, since + * they will be generated if the user scrolls quickly. + */ + if ((grab_widget == event_widget) && + (event->button.button == 4 || event->button.button == 5)) + { + GtkWidget *range = NULL; + GtkWidget *scrollwin; + + if (GTK_IS_RANGE (event_widget)) + range = event_widget; + else + { + scrollwin = gtk_widget_get_ancestor (event_widget, + GTK_TYPE_SCROLLED_WINDOW); + if (scrollwin) + range = GTK_SCROLLED_WINDOW (scrollwin)->vscrollbar; + } + + if (range && GTK_WIDGET_VISIBLE (range)) + { + if (event->type == GDK_BUTTON_PRESS) + { + GtkAdjustment *adj = GTK_RANGE (range)->adjustment; + gfloat new_value = adj->value + ((event->button.button == 4) ? + -adj->page_increment / 2: + adj->page_increment / 2); + new_value = CLAMP (new_value, adj->lower, adj->upper - adj->page_size); + gtk_adjustment_set_value (adj, new_value); + } + break; + } + } + gtk_propagate_event (grab_widget, event); + break; + case GDK_KEY_PRESS: case GDK_KEY_RELEASE: if (key_snoopers) @@ -685,9 +728,6 @@ gtk_main_do_event (GdkEvent *event) } /* else fall through */ case GDK_MOTION_NOTIFY: - case GDK_BUTTON_PRESS: - case GDK_2BUTTON_PRESS: - case GDK_3BUTTON_PRESS: case GDK_BUTTON_RELEASE: case GDK_PROXIMITY_IN: case GDK_PROXIMITY_OUT: diff --git a/gtk/gtkviewport.c b/gtk/gtkviewport.c index 168ff0317d..6964206fe1 100644 --- a/gtk/gtkviewport.c +++ b/gtk/gtkviewport.c @@ -430,7 +430,9 @@ gtk_viewport_realize (GtkWidget *widget) attributes.colormap = gtk_widget_get_colormap (widget); event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK; - attributes.event_mask = event_mask; + /* We select on button_press_mask so that button 4-5 scrolls are trapped. + */ + attributes.event_mask = event_mask | GDK_BUTTON_PRESS_MASK; attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; -- 2.30.2